﻿App.CutTruckerQuery = function() {
    return {

        currentFormValues: {},

        getStore: function() {
            var store = new Ext.data.Store({
                autoLoad:true,
				baseParams : {start:0, limit:25},
				proxy: new Ext.data.HttpProxy({
					url : 'cuttrucker/getallcuttrucker'
				}),
                remoteSort: false,
				reader: new Ext.data.JsonReader({
					totalProperty : 'totalCount',
					root : 'rows',
					idProperty : 'object_id',
					fields: [{
						name: 'object_id',
						type: 'string'
					},{
						name:'objid',
						type:"string"
					},
					{
						name :'obj_name',
						type:'string'
					},
					{
						name :'obj_num',
						type:'string'
					},
					{
						name :'local_name',
						type:'string'
					},
					{
						name: 'name',
						type:'string'
					},
					{
						name: 'cuttrucker_phone',
						type:'string'
					},
					{
						name: 'cuttrucker_time',
						type:'string'
					}]
				})
            });
            return store;
        },

        createGrid: function(id) {

            var panel = Ext.getCmp(id);

            panel.body.dom.innerHTML = "";

            var sm = new Ext.grid.CheckboxSelectionModel();
            this.grid = new Ext.grid.GridPanel({
            	anchor:'top 50%',
                loadMask: true,
                stripeRows: true,
                tbar: new Ext.PagingToolbar({ 
                	pageSize: 25 ,//分页必须加的参数.最好和store里面的limit保持一致
                	displayInfo: true,
                    store: this.store,
                    items:[
                    /*{
	                    text: '增加',
	                    scope: this,
	                    handler: this.add
	                },
	                {
	                    text: '删除',
	                    scope: this,
	                    handler: this.del
                },*/'-', new Ext.ux.form.SearchField({
                    store: this.store,
                    width: 110
                })]}),
                title:"接车查询",//打印必须设置tile
                plugins: [Ext.ux.plugins.Print],//打印按钮
                loadMask: true,
                viewConfig : {autoFill:false,forceFit:true},
                autoHeight:true,
                store: this.store,
                sm: sm,
                columns: [sm, new Ext.grid.RowNumberer(),{
                    header: "货号",
                    width: 60,
                    sortable: true,
                    dataIndex: 'objid',
                    renderer: this.highLight
                },
                {
                    header: "货物名称",
                    width: 60,
                    sortable: true,
                    dataIndex: 'obj_name',
                    renderer: this.highLight
                },
                {
                    header: "件数",
                    width: 60,
                    sortable: true,
                    dataIndex: 'obj_num'
                },
                {
                    header: "接车地点",
                    width: 100,
                    sortable: true,
                    dataIndex: 'local_name'
                },
                {
                    header: "接车人",
                    width: 100,
                    sortable: true,
                    dataIndex: 'name',
                    renderer: this.highLight
                },
                {
                    header: "接车人电话",
                    width: 100,
                    sortable: true,
                    dataIndex: 'cuttrucker_phone',
                    renderer: this.highLight
                },{
                    header: "接车时间",
                    width: 100,
                    sortable: true,
                    dataIndex: 'cuttrucker_time',
                    renderer: this.highLight
                }]
            });
            panel.add(this.grid);

        },
        highLight: function(value) {
        	var key = App.CutTruckerQuery.grid.store.baseParams.query;
        	var v = value ? value.toString() : '';
        	if (Ext.isString(v) & Ext.isString(key)) {
        		if (key.length > 0) {
        			var re = new RegExp(key, "g");
        			return v.replace(re, "<span style='color:red;background-color:yellow;'>" + key + "</span>");
        		} else {
        			return v;
        		}
        	} else {
        		return v;
        	}
        },

        render: function(id) {
            if (!this.store) {
                this.store = this.getStore();
            };
            this.createGrid(id);

        }
    };
} ();
